package com.example.goodsserver.controller;

import com.example.goodsserver.params.CollectionParams;
import com.example.goodsserver.params.PageCollectionParams;
import com.example.goodsserver.service.CollectionService;
import com.example.goodsserver.vo.CollectionVO;
import com.example.userserver.enums.ReturnEnum;
import com.example.userserver.vo.Result;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/collection-server")
@Api(tags = "收藏接口")
public class CollectionController {
    @Autowired
    private CollectionService collectionService;

    @ApiOperation(value = "获取分页收藏")
    @PostMapping(value = "/page")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result<PageInfo<CollectionVO>> pageCollection(@RequestBody PageCollectionParams pageCollectionParams) {
        return new Result(collectionService.pageCollection(pageCollectionParams), ReturnEnum.SUCCESS);
    }

    @ApiOperation(value = "删除收藏")
    @DeleteMapping(value = "/delete")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result deleteCollection(@RequestParam String id) {
        collectionService.deleteCollection(id);
        return new Result(null, ReturnEnum.SUCCESS);
    }

    @ApiOperation(value = "新增收藏")
    @PutMapping(value = "/insert")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result insertCollection(@RequestBody CollectionParams collectionParams) {
        return collectionService.insertCollection(collectionParams);
    }

}
